import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-01-22
 * Time: 15:58
 */
public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[10];
    }
    public void push(int val) {
      if(isFull()) {
          elem = Arrays.copyOf(elem,2 * elem.length);
      }
      elem[usedSize] = val;
      usedSize++;
    }


    public boolean isFull() {
       return usedSize == elem.length;
    }
    //出栈
    public int pop() throws EmptyException{
        if(isEmpty()) {
            throw new EmptyException("栈为空");
        }
        int b = elem[usedSize-1];
        usedSize--;
        return b;

    }
    public boolean isEmpty() {
        return usedSize == 0;
    }

    public int peek() throws EmptyException{
        if(isEmpty()) {
            throw new EmptyException("栈为空");
        }
        int val = elem[usedSize-1];
        return  val;
}
}
